package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.MakeFriendManager;
import com.itheima.app.manager.MessageManager;
import com.itheima.domain.vo.HuanXinVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@RestController
public class MessageController {

    @Autowired
    private MessageManager messageManager;

    //查询陌生人问题
    @GetMapping("/tanhua/strangerQuestions")
    public ResponseEntity findStrangerQuestions(Long userId) throws IOException {

        return messageManager.findStrangerQuestions(userId);
    }

    //查询别人的问题
    @GetMapping("/huanxin/user")
    public ResponseEntity getHuanxinUser() {
        Long localUserId = UserHolder.getLocalUserId();
        HuanXinVo huanXinVo = new HuanXinVo();
        huanXinVo.setUsername("HX" + localUserId);
        huanXinVo.setPassword("123456");
        System.out.println("app端获得环信的数据:" + huanXinVo);
        return ResponseEntity.ok(huanXinVo);
    }

    //回答(发给环信)别人陌生人问题
    @PostMapping("/tanhua/strangerQuestions")
    public ResponseEntity findAnserStrangerQuestions(@RequestBody Map<String, String> map) {
        String userId = map.get("userId");
        String reply = map.get("reply");
        System.out.println("map--"+map);
        return messageManager.findAnserStrangerQuestions(Long.valueOf(userId), reply);

    }
//加好友
    @PostMapping("/messages/contacts")
    public ResponseEntity addContacts(@RequestBody Map<String ,Long> map){
        Long friendId = map.get("userId");
        return messageManager.addContacts(friendId);

    }

    //联系人列表
    @GetMapping("/messages/contacts")
    public ResponseEntity contactList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize
    ) throws IOException {

        return messageManager.findContactList(page , pagesize);
    }

    // 点赞列表
    @GetMapping("/messages/likes")
    public ResponseEntity likes(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize
    ) {
        Long commentType = 1L;
        return messageManager.findInfo(page , pagesize , commentType);
    }
    // 评论列表
    @GetMapping("/messages/comments")
    public ResponseEntity comments(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize
    ) {
        Long commentType = 2L;
        return messageManager.findInfo(page , pagesize , commentType);
    }

    // 喜欢列表
    @GetMapping("/messages/loves")
    public ResponseEntity loves(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize
    ) {
        Long commentType = 3L;
        return messageManager.findInfo(page , pagesize , commentType);
    }

    @GetMapping("/messages/announcements")
    public ResponseEntity getAnnouncements(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize
    ) {
        return messageManager.getAnnouncements(page , pagesize );
    }
}
